package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.ModulesService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ModulesAddVO;
import com.junzhiit.nengji.cms.web.vo.ModulesEditVO;
import com.junzhiit.nengji.cms.web.vo.ModulesListVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/modules")
public class ModulesController extends BaseController {

	@Autowired
	private ModulesService modulesService;

	@ApiOperation(value = "查询总部所有模块")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp, ModulesListVO modulesListVO,String sessionId) {
		AssertUtil.notBlank(sessionId, "sessionId is required.");
		return modulesService.findAll(dtp, modulesListVO,sessionId);
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResultVO findById(@PathVariable String id) {
		return modulesService.findById(id);
	}

	@ApiOperation(value = "模块添加")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(ModulesAddVO modulesAddVO,String sessionId) {
		AssertUtil.notBlank(sessionId, "sessionId is required.");
		AssertUtil.notBlank(modulesAddVO.getName(), "name is required.");
		AssertUtil.notNull(modulesAddVO.getColumnId(), "columnId is required.");
		AssertUtil.notNull(modulesAddVO.getGoodsQuantity(), "goodsQuantity is required.");
		AssertUtil.notNull(modulesAddVO.getGoodsExhibitionQuantity(), "goodsExhibitionQuantity is required.");
		return modulesService.add(modulesAddVO,sessionId);

	}

	@ApiOperation(value = "模块修改")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO edit(ModulesEditVO modulesEditVO) {
		return modulesService.edit(modulesEditVO);
	}

	@ApiOperation(value = "删除模块")
	@RequestMapping(value = "/del", method = RequestMethod.PUT)
	public ResultVO del(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return modulesService.del(id);
	}
	
	@ApiOperation(value = "获取全部模块" )
	@RequestMapping(value="/all",method=RequestMethod.GET)
	public ResultVO getAll(){
		return modulesService.getAll();
	}

}
